﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using 数据验证;

namespace 热更验证
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        int index = 0; //项目索引
        bool checkKey = true; //检查核心文件是否存在
        string oldPath = Directory.GetCurrentDirectory() + @"\Xml.xml"; //项目地址库
        Type types = typeof(Riyue); //默认项目类型日月
        string[] pathList = null; //通用地址列表

        //一级列表
        /// <summary>
        /// XML目录
        /// </summary>
        string xPath;
        /// <summary>
        /// 精灵属性列表 
        /// </summary>
        string petPath;

        //二级列表
        /// <summary>
        /// 成长技能索引
        /// </summary>
        string growSkillPath;
        /// <summary>
        /// 学习机索引
        /// </summary>
        string studySkillPath;
        /// <summary>
        /// 精灵特性索引
        /// </summary>
        string pmCharacteristicPath;
        /// <summary>
        /// 进化石返还道具 日月/决斗
        /// </summary>
        string resetEvolutionListPath;
        /// <summary>
        /// 升星条件索引
        /// </summary>
        string starConditionPath;
        /// <summary>
        /// 进化消耗道具索引 日月 （决斗只有M2才有进化物品消耗）
        /// </summary>
        string evolutionConditionPath;
        /// <summary>
        /// 性格洗练条件 决斗
        /// </summary>
        string pokeCharacterClearPath;
        /// <summary>
        /// Mega强化11级特性 决斗
        /// </summary>
        string megaLvSysPath;
        /// <summary>
        /// 物品掉落索引 新逆袭 （0，6）
        /// </summary>
        string dropPath;
        /// <summary>
        /// 精灵分解掉落 决斗/新喵喵
        /// </summary>
        string disintegratePath;
        /// <summary>
        /// NPC掉落 
        /// </summary>
        string npcListPath;


        //三级列表
        /// <summary>
        /// 升星消耗道具索引
        /// </summary>
        string starItemListPath;
        /// <summary>
        /// 升星节点消耗 决斗/新喵喵 （0，5）
        /// </summary>
        string starContentPath;
        /// <summary>
        /// 升星材料 决斗/新喵喵 （0，3，5）
        /// </summary>
        string starLevelCostPath;
        


        //四级列表
        /// <summary>
        /// 种族值分配值
        /// </summary>
        string abilityPath;
        /// <summary>
        /// 所有道具
        /// </summary>
        string itemsPath;
        /// <summary>
        /// 所有技能
        /// </summary>
        string pmMovePath;
        /// <summary>
        /// 所有特性
        /// </summary>
        string pmAbilityPath; 


        XmlDocument xmlDoc = null;

        Hashtable petSeriseTable = null;
        Hashtable psIDTable = null;
        HashK<string, string> pmAbilityHK = null;
        HashK<string, string> petNameHK = null;
        HashK<string, string> pmMoveHK = null;
        HashK<string, bool> gskillHK = null;
        HashK<string, bool> sskillHK = null;
        HashK<string, string> itemsHK = null;
        HashK<string, string> starConditionHK = null;
        HashK<string, string> pokeCharacterClearHK = null;
        HashK<string, string> megaLvSysHK = null;
        HashK<string, string> starContentHK = null;
        HashK<string, string> dropHK = null;
        HashK<string, string> starLevelCostHK = null;
        HashK<string, StringBuilder> pmCharacteristicHK = null;
        HashK<string, string> evolutionConditionHK = null;
        HashK<string, Ability> abilityHK = null;
        HashK<string, StarItemList> starItemListHK = null;
        HashK<string, ResetEvolutionList> resetEvolutionListHK = null;
        HashK<string, Disintegrate> disintegrateHK = null;
        HashK<string, StarCondition> starCondition2HK = null;
        Dictionary<string, FieldInfo> petTypeDic = null;

        public delegate void Loader();


        /// <summary>
        /// 设置 通用 核心文件地址
        /// </summary>
        string[] SetPath()
        {
            xPath = XPath_textBox.Text;
            petPath = xPath + @"\pets.xml";
            growSkillPath = xPath + @"\growSkill.xml";
            studySkillPath = xPath + @"\studySkill.xml";
            pmCharacteristicPath = xPath + @"\pmCharacteristic.xml";
            abilityPath = xPath + @"\ability.xml";
            itemsPath = xPath + @"\items.xml";
            pmMovePath = xPath + @"\pmMove.xml";
            pmAbilityPath = xPath + @"\pmAbility.xml";
            evolutionConditionPath = xPath + @"\evolutionCondition.xml";
            starConditionPath = xPath + @"\starCondition.xml";
            dropPath = xPath + @"\drop.xml";
            npcListPath = xPath + @"\npcList.xml";

            string[] pathList = {
                petPath, growSkillPath, studySkillPath, pmCharacteristicPath, abilityPath,itemsPath,
                pmAbilityPath, evolutionConditionPath, starConditionPath,pmMovePath,dropPath,npcListPath
            };

            return pathList;
        }

        /// <summary>
        /// 设置 日月 专属文件地址
        /// </summary>
        string[] SetRiyuePath()
        {
            resetEvolutionListPath = xPath + @"\resetEvolutionList.xml"; //日月进化石返还
            starItemListPath = xPath + @"\starItemList.xml"; //日月升星材料

            string[] RiyuePath = { resetEvolutionListPath, starItemListPath };

            return RiyuePath;
        }

        /// <summary>
        /// 设置 决斗 专属文件地址
        /// </summary>
        string[] SetJuedouPath()
        {
            pokeCharacterClearPath = xPath + @"\pokeCharacterClear.xml"; //性格洗练
            megaLvSysPath = xPath + @"\megaLvSys.xml"; //决斗M等级强化特性
            starContentPath = xPath + @"\starContent.xml"; //升星节点消耗
            starLevelCostPath = xPath + @"\starLevelCost.xml"; //升星材料
            disintegratePath = xPath + @"\disintegrate.xml"; //精灵分解

            string[] JuedouPath = { pokeCharacterClearPath, megaLvSysPath, starContentPath, starLevelCostPath , disintegratePath };

            return JuedouPath;
        }

        /// <summary>
        /// 设置 新喵喵 专属文件地址
        /// </summary>
        string[] SetXinmiaomiaoPath()
        {
            starContentPath = xPath + @"\starContent.xml";  //升星节点消耗
            starLevelCostPath = xPath + @"\starLevelCost.xml"; //升星材料
            pokeCharacterClearPath = xPath + @"\pokeCharacterClear.xml"; //性格洗练
            disintegratePath = xPath + @"\disintegrate.xml"; //精灵分解

            string[] XinmiaomiaoPath = { starContentPath, starLevelCostPath ,pokeCharacterClearPath , disintegratePath };

            return XinmiaomiaoPath;
        }

        /// <summary>
        /// 设置 新逆袭 专属文件地址
        /// </summary>
        string[] SetXinnixiPath()
        {
            starItemListPath = xPath + @"\starItemList.xml"; //日月升星材料
            
            string[] XinmiaomiaoPath = { starItemListPath };

            return XinmiaomiaoPath;
        }

        /// <summary>
        /// 设置 新世代 专属文件地址
        /// </summary>
        string[] SetXinshidaiPath()
        {
            starContentPath = xPath + @"\starContent.xml"; //升星节点消耗
            starLevelCostPath = xPath + @"\starLevelCost.xml"; //升星材料

            string[] XinmiaomiaoPath = { starContentPath, starLevelCostPath };

            return XinmiaomiaoPath;
        }

        /// <summary>
        /// 判断重要文件是否有效
        /// </summary>
        bool CheckPath()
        {
            pathList = SetPath();

            for (int i = 0; i < pathList.Length; i++)
            {
                if (!File.Exists(pathList[i]))
                {
                    checkKey = false;
                    InfoText("无效路径：" + pathList[i]);
                }
            }

            switch (index)
            {
                case 0: //日月
                    string[] riyuePath = SetRiyuePath();

                    for (int i = 0; i < riyuePath.Length; i++)
                    {
                        if (!File.Exists(riyuePath[i]))
                        {
                            checkKey = false;
                            InfoText("无效路径：" + riyuePath[i]);
                        }
                    }
                    
                    if (checkKey)
                    {
                        Loader dele1 = LoadResetEvolutionList;
                        dele1 += LoadStarItemList;
                        dele1();
                    }
                    break;

                case 1: //决斗
                    string[] juedouPath = SetJuedouPath();

                    for (int i = 0; i < juedouPath.Length; i++)
                    {
                        if (!File.Exists(juedouPath[i]))
                        {
                            checkKey = false;
                            InfoText("无效路径：" + juedouPath[i]);
                        }
                    }

                    if (checkKey)
                    {
                        Loader dele1 = LoadPokeCharacter;
                        dele1 += LoadMegaLvSys;
                        dele1 += LoadStarContent;
                        dele1 += LoadStarLevelCost;
                        dele1 += LoadDisintegrate;
                        dele1();
                    }
                    break;

                case 2: //新喵喵
                    string[] xinmiaomiaoPath = SetXinmiaomiaoPath();

                    for (int i = 0; i < xinmiaomiaoPath.Length; i++)
                    {
                        if (!File.Exists(xinmiaomiaoPath[i]))
                        {
                            checkKey = false;
                            InfoText("无效路径：" + xinmiaomiaoPath[i]);
                        }
                    }

                    if (checkKey)
                    {
                        Loader dele1 = LoadStarContent;
                        dele1 += LoadStarLevelCost;
                        dele1 += LoadPokeCharacter;
                        dele1 += LoadDisintegrate;
                        dele1();
                    }
                    break;

                case 3: //新逆袭
                    string[] xinnixiPath = SetXinnixiPath();

                    for (int i = 0; i < xinnixiPath.Length; i++)
                    {
                        if (!File.Exists(xinnixiPath[i]))
                        {
                            checkKey = false;
                            InfoText("无效路径：" + xinnixiPath[i]);
                        }
                    }

                    if (checkKey)
                    {
                        Loader dele1 = LoadStarItemList;
                        dele1 += LoadDrop;
                        dele1();
                    }

                    break;

                case 4: //新世代
                    string[] xinshidaiPath = SetXinshidaiPath();

                    for (int i = 0; i < xinshidaiPath.Length; i++)
                    {
                        if (!File.Exists(xinshidaiPath[i]))
                        {
                            checkKey = false;
                            InfoText("无效路径：" + xinshidaiPath[i]);
                        }
                    }

                    if (checkKey)
                    {
                        Loader dele1 = LoadStarContent;
                        dele1 += LoadStarLevelCost;
                        dele1 += LoadDrop;
                        dele1();
                    }

                    break;

                case 5: //通用类型日月
                    string[] koudaiPath = SetRiyuePath();

                    for (int i = 0; i < koudaiPath.Length; i++)
                    {
                        if (!File.Exists(koudaiPath[i]))
                        {
                            checkKey = false;
                            InfoText("无效路径：" + koudaiPath[i]);
                        }
                    }

                    if (checkKey)
                    {
                        Loader dele1 = LoadResetEvolutionList;
                        dele1 += LoadStarItemList;
                        dele1();
                    }

                    break;
            }

            if (checkKey)
            {
                Loader dele1 = LoadPet;
                dele1 += LoadPmMove;
                dele1 += LoadPetName;
                dele1 += LoadStarCondition;
                dele1 += LoadAbility;
                dele1 += LoadSkill;
                dele1 += LoadPmAbility;
                dele1 += LoadItems;
                dele1 += LoadPmCharacteristic;
                dele1 += LoadEvolutionCondition;
                dele1();
                InfoText("LoadXml完毕.");
                check_button.Enabled = true;
                dropLevel_button.Enabled = true;
                return true;
            }
            else
            {
                MessageBox.Show("缺少核心文件，请检查当前路径是否有效！", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                check_button.Enabled = false;
                return false;
            }
        }

        /// <summary>
        /// 1.选择查询项目
        /// </summary>
        private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            //控件内容清理
            X_listView.Clear();
            ab_listView.Clear();
            XPath_textBox.Clear();
            info_richTextBox.Clear();

            //核心文件开关初始化
            checkKey = true;

            //各文档初始化
            xmlDoc = null;

            //清理各个数据缓存列表
            petSeriseTable = null;
            psIDTable = null;
            petNameHK = null;
            pmAbilityHK = null;
            abilityHK = null;
            pmMoveHK = null;
            gskillHK = null;
            sskillHK = null;
            resetEvolutionListHK = null;
            starConditionHK = null;
            starItemListHK = null;
            pmCharacteristicHK = null;
            evolutionConditionHK = null;
            pokeCharacterClearHK = null;
            megaLvSysHK = null;
            starContentHK = null;
            starLevelCostHK = null;
            dropHK = null;
            disintegrateHK = null;
            starCondition2HK = null;

            //类型字典初始化
            petTypeDic = null;

            pathList = null;

            index = comboBox.SelectedIndex;
            XPath_textBox.ReadOnly = false;

            switch (index)
            {
                case 0:
                    types = typeof(Riyue);
                    InfoText("********日月********");
                    break;

                case 1:
                    types = typeof(Juedou);
                    InfoText("********决斗********");
                    break;

                case 2:
                    types = typeof(Xinmiaomiao);
                    InfoText("********新喵喵********");
                    break;

                case 3:
                    types = typeof(Xinnixi);
                    InfoText("********新逆袭********");
                    break;

                case 4:
                    types = typeof(Xinshidai);
                    InfoText("********新世代********");
                    break;

                case 5:
                    types = typeof(RiyueTY);
                    InfoText("********日月通用********");
                    break;
            }
            
            //检查地址库文件是否存在
            if (File.Exists(oldPath))
            {
                //获取历史地址信息
                XPath_button.Enabled = true;
                xmlDoc = new XmlDocument();
                xmlDoc.Load(oldPath);
                XmlElement root = xmlDoc.DocumentElement;
                XmlNodeList nodeList = root.ChildNodes;
                foreach (XmlNode item in nodeList)
                {
                    string id = item.Attributes["ID"].Value;
                    if (id == index.ToString())
                    {
                        string path = item.ChildNodes.Item(0).InnerText;
                        if (string.IsNullOrEmpty(path))
                        {
                            InfoText("*无历史地址信息*");
                            check_button.Enabled = false;
                        }
                        else
                        {
                            if (Directory.Exists(path))
                            {
                                XPath_textBox.Text = path;
                                XmlXCheck_button.Enabled = true;
                                getxml_button.Enabled = true;
                                timebutton.Enabled = true;
                            }
                            else InfoText("*历史地址信息无效，请选择有效路径*");
                        }
                    }
                }
                xmlDoc.Save(oldPath);
            }
            else
            {
                //创建地址库文件
                XPath_button.Enabled = true;
                check_button.Enabled = false;
                using (File.Create(oldPath)) InfoText("*新建地址库文件成功*");
                xmlDoc = new XmlDocument();
                XmlDeclaration declaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8",null);
                XmlElement root = xmlDoc.CreateElement("list");
                xmlDoc.AppendChild(declaration);
                xmlDoc.AppendChild(root);
                for (int i = 0; i < comboBox.Items.Count; i++)
                {
                    XmlElement createElement = xmlDoc.CreateElement("id");
                    XmlElement path = xmlDoc.CreateElement("path");
                    path.InnerText = "";
                    createElement.SetAttribute("ID", i.ToString());
                    createElement.AppendChild(path);
                    root.AppendChild(createElement);
                }
                xmlDoc.Save(oldPath);
            }
        }

        /// <summary>
        /// 2.获取XML文档地址
        /// </summary>
        private void XPath_button_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog.ShowDialog() == DialogResult.OK) XPath_textBox.Text = folderBrowserDialog.SelectedPath;
        }

        /// <summary>
        /// 3.检查文档路径是否有效
        /// </summary>
        private void XPath_textBox_TextChanged(object sender, EventArgs e)
        {
            string path = XPath_textBox.Text;
            if (!String.IsNullOrEmpty(path))
            {
                if (Directory.Exists(path))
                {
                    checkKey = true;
                    if (!CheckPath()) return;
                    ChangePath();
                    XmlXCheck_button.Enabled = true;
                    getxml_button.Enabled = true;
                    timebutton.Enabled = true;
                }
                else
                {
                    MessageBox.Show("路径无效", "警告", MessageBoxButtons.OK,MessageBoxIcon.Error);
                    return;
                }
            }
            

        }

        /// <summary>
        /// 4.查询精灵
        /// </summary>
        private void check_button_Click(object sender, EventArgs e)
        {
            string petID = Name_textBox.Text;
            petID = petID.Trim();
            string petID2 = "";
            int tempID;
            bool key = true; //false表示petID为文字，true为数字

            if (String.IsNullOrEmpty(petID)) //判断输入是否为空
            {
                MessageBox.Show("0.输入不能为空，请重新输入", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (!Int32.TryParse(petID,out tempID)) //判断输入是否非数字
            {
                if (petNameHK.ContainsKey(petID))
                {
                    petID2 = petNameHK.GetTvalue(petID);
                    petID2 = petID2.Trim();
                    key = false; 
                }
                else
                {
                    MessageBox.Show("1.精灵名字 错误，请重新输入", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

            }
            if (index == 3)
            {
                object obj ;
                string nextID = "";
                string prePetId = "";
                string petIDTemp = "";
                SortedList<string, object> petlist = new SortedList<string, object>();

                switch (key)
                {
                    case true: //为数字型字符串时
                        if (psIDTable.ContainsKey(petID))
                        {
                            petIDTemp = petID;
                            nextID = petSeriseTable[petID].ToString();
                            prePetId = (Int32.Parse(petID) - 1).ToString();
                            obj = psIDTable[petID];
                            petlist.Add(petID, obj);
                        }
                        else
                        {
                            MessageBox.Show("2.精灵ID 错误，请重新输入", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        break;
                    case false: //为文字型字符串时
                        if (psIDTable.ContainsKey(petID2))
                        {
                            petIDTemp = petID2;
                            nextID = petSeriseTable[petID2].ToString();
                            prePetId = (Int32.Parse(petID2) - 1).ToString();
                            obj = psIDTable[petID2];
                            petlist.Add(petID2, obj);
                        }
                        else
                        {
                            MessageBox.Show("3.精灵ID 错误，请重新输入", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        break;
                }

                //前置精灵ID
                if (petSeriseTable.ContainsKey(prePetId))
                {
                    while (petSeriseTable[prePetId].ToString() == petIDTemp)
                    {
                        petIDTemp = prePetId;
                        prePetId = (Int32.Parse(petIDTemp) - 1).ToString();
                        obj = psIDTable[petIDTemp];
                        petlist.Add(petIDTemp, obj);
                    }
                }

                //进化ID
                string last = default;
                if (nextID == "0")
                {
                    obj = psIDTable[petIDTemp];
                    last = petTypeDic["MegaPetId"].GetValue(obj).ToString();
                    while (psIDTable.ContainsKey(last))
                    {
                        obj = psIDTable[last];
                        petlist.Add(last, obj);
                        last = petTypeDic["MegaPetId"].GetValue(obj).ToString();
                    }
                }
                else
                {
                    while (petSeriseTable.ContainsKey(nextID))
                    {
                        petIDTemp = nextID;
                        nextID = petSeriseTable[petIDTemp].ToString();
                        obj = psIDTable[petIDTemp];
                        petlist.Add(petIDTemp, obj);
                        if (nextID == "0")
                        {
                            last = petTypeDic["MegaPetId"].GetValue(obj).ToString();
                            while (psIDTable.ContainsKey(last))
                            {
                                obj = psIDTable[last];
                                petlist.Add(last, obj);
                                last = petTypeDic["MegaPetId"].GetValue(obj).ToString();
                            }
                        }
                    }
                }
                for (int i = 0; i < petlist.Values.Count; i++) SetListViewItem(petlist.Values[i]);
                //foreach (var item in petlist.Values) SetListViewItem(item);
                SetListViewItem2();
            }
            else
            {
                string seriseID = "";
                switch (key)
                {
                    case true:
                        if (psIDTable.ContainsKey(petID))
                        {
                            seriseID = psIDTable[petID].ToString();
                        }
                        else
                        {
                            MessageBox.Show("精灵ID 错误，请重新输入", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        break;
                    case false:
                        if (psIDTable.ContainsKey(petID2))
                        {
                            seriseID = psIDTable[petID2].ToString();
                        }
                        else
                        {
                            MessageBox.Show("精灵ID 错误，请重新输入", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        break;
                }
                List<object> objlist = petSeriseTable[seriseID] as List<object>;
                for (int i = 0; i < objlist.Count; i++) SetListViewItem(objlist[i]);
                //foreach (var item in objlist) SetListViewItem(item);
                SetListViewItem2();
            }

            void SetListViewItem2()
            {
                this.X_listView.BeginUpdate();
                this.ab_listView.BeginUpdate();

                ListViewItem lvi = new ListViewItem();
                ListViewItem lvi2 = new ListViewItem();

                for (int i = 0; i < X_listView.Columns.Count; i++)
                {
                    lvi.SubItems.Add("");
                }

                for (int i = 0; i < ab_listView.Columns.Count; i++)
                {
                    lvi2.SubItems.Add("");
                }

                //为数据列表添加一行数据
                this.X_listView.Items.Add(lvi);
                this.ab_listView.Items.Add(lvi2);

                //结束数据处理，UI界面一次性绘制
                this.X_listView.EndUpdate();
                this.ab_listView.EndUpdate();
            }

            InfoText("~查询完毕~");
        }

        /// <summary>
        /// 5.查询单个XML文档是否存在重复ID
        /// </summary>
        private void XmlXCheck_button_Click(object sender, EventArgs e)
        {
            string name = XmlName_textBox.Text;
            string index = XmlIndex_textBox.Text;
            string patx = XPath_textBox.Text;
            string XmlPath = patx + @"\" + name + @".xml";
            int i;

            //检查输入是否有效值
            if (String.IsNullOrEmpty(patx) || String.IsNullOrEmpty(name) || String.IsNullOrEmpty(index))
            {
                MessageBox.Show("输入存在有空值！\n请检查： \n文件路径（XML位置）\n文件名（XML名称无需加后缀）\n索引位置（索引从0开始，第一个字段为0，第二个为1，依次类推） ", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            
            //检查索引是否为有效数字，并返回 int 类型索引 i
            if (!Int32.TryParse(index, out i))
            {
                MessageBox.Show("输入的索引值错误，请输入数字索引", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //检查文件地址是否正确
            if (!File.Exists(XmlPath))
            {
                InfoText("文件无效，请检查文件名: " + XmlPath);
                MessageBox.Show("文件无效，请检查文件名", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            InfoText("**************开始校对**************");
            XmlLoader loader = new XmlLoader(XmlPath, i);
            if (loader.IsRepeate())
            {
                HashSet<string> list = loader.GetRepeate();
                foreach (var item in list) InfoText(name + " 重复 " + loader.GetKey() + " ID：" + item);
            }
            InfoText("**************校对完毕**************");
            MessageBox.Show("校对完毕", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        /// <summary>
        /// 6.验证升星升阶跳转
        /// </summary>
        private void button1_Click(object sender, EventArgs e)
        {
            HashK<string, string> items_dropLevelList_hashK = new HashK<string, string>();
            HashK<string, string> npcListhashK = new HashK<string, string>();
            HashK<string, StringBuilder> drophashK = new HashK<string, StringBuilder>();
            int count = 20;
            string[] str = new string[count];
            for (int i = 0; i < count; i++)
            {
                string temp;
                if (i < 10) temp = "40000000" + i.ToString();
                else temp = "4000000" + i.ToString();
                str[i] = temp;
            }
            HashSet<string> set = new HashSet<string>(str);
            using (XmlTextReader reader = new XmlTextReader(itemsPath))
            {
                reader.WhitespaceHandling = WhitespaceHandling.None;
                string itemId = "";
                string dropLevelList = "";
                while (reader.Read())
                {
                    reader.ReadToFollowing("itemType");
                    if (reader.ReadString() == "5" & reader.EOF == false)
                    {
                        reader.ReadToFollowing("itemId");
                        itemId = reader.ReadString();
                        reader.ReadToFollowing("dropLevelList");
                        dropLevelList = reader.ReadString();
                        if (dropLevelList != "0")
                        {
                            if (!items_dropLevelList_hashK.ContainsKey(itemId)) items_dropLevelList_hashK.Add(itemId, dropLevelList);
                        }
                    }
                }
            }

            using (XmlTextReader reader = new XmlTextReader(npcListPath))
            {
                reader.WhitespaceHandling = WhitespaceHandling.None;
                string npcId = "";
                string dropId = "";
                while (reader.Read())
                {
                    reader.ReadToFollowing("npcId");
                    npcId = reader.ReadString();
                    reader.ReadToFollowing("dropId");
                    dropId = reader.ReadString();
                    if (reader.EOF == false & dropId != "0")
                    {
                        if (!npcListhashK.ContainsKey(npcId)) npcListhashK.Add(npcId, dropId);
                        else InfoText("npcList/npcId 重复：" + npcId);
                    }
                }
            }

            using (XmlTextReader reader = new XmlTextReader(dropPath))
            {
                reader.WhitespaceHandling = WhitespaceHandling.None;
                string dropId = "";
                string temp = "";
                StringBuilder builder = new StringBuilder();
                while (reader.Read())
                {
                    reader.ReadToFollowing("dropId");
                    dropId = reader.ReadString();
                    if (reader.EOF == false)
                    {
                        reader.ReadToFollowing("item_1");
                        temp = reader.ReadString();
                        if (temp != "0") builder.Append(temp);

                        reader.ReadToFollowing("item_2");
                        temp = reader.ReadString();
                        if (temp != "0") builder.Append("," + temp);

                        reader.ReadToFollowing("item_3");
                        temp = reader.ReadString();
                        if (temp != "0") builder.Append("," + temp);

                        reader.ReadToFollowing("item_4");
                        temp = reader.ReadString();
                        if (temp != "0") builder.Append("," + temp);

                        reader.ReadToFollowing("item_5");
                        temp = reader.ReadString();
                        if (temp != "0") builder.Append("," + temp);

                        reader.ReadToFollowing("item_6");
                        temp = reader.ReadString();
                        if (temp != "0") builder.Append("," + temp);

                        reader.ReadToFollowing("item_7");
                        temp = reader.ReadString();
                        if (temp != "0") builder.Append("," + temp);

                        reader.ReadToFollowing("item_8");
                        temp = reader.ReadString();
                        if (temp != "0") builder.Append("," + temp);

                        reader.ReadToFollowing("item_9");
                        temp = reader.ReadString();
                        if (temp != "0") builder.Append("," + temp);

                        reader.ReadToFollowing("item_10");
                        temp = reader.ReadString();
                        if (temp != "0") builder.Append("," + temp);

                        if (!drophashK.ContainsKey(dropId))
                        {
                            drophashK.Add(dropId, builder);
                            builder = new StringBuilder();
                        }
                    }
                }
            }

            foreach (string item in items_dropLevelList_hashK.Keys)
            {
                string dropLevelList = items_dropLevelList_hashK.GetTvalue(item);
                string[] dropLevel = dropLevelList.Split(';');
                StringBuilder builder;
                string temp = "";
                for (int i = 0; i < dropLevel.Length; i++)
                {
                    if (!set.Contains(dropLevel[i]))
                    {
                        if (npcListhashK.ContainsKey(dropLevel[i]))
                        {
                            string dropId = npcListhashK.GetTvalue(dropLevel[i]);
                            if (drophashK.ContainsKey(dropId))
                            {
                                builder = drophashK.GetTvalue(dropId);
                                if (!((builder.ToString()).Contains(item)))
                                {
                                    if (temp != item)
                                    {
                                        InfoText("itemID掉落跳转异常：" + item);
                                        temp = item;
                                    }
                                }
                            }
                            else InfoText("npcList/dropId 不在drop表中：" + dropId);
                        }
                        else InfoText("items/dropLevelList 不在npcList表中：" + dropLevelList);
                    }
                }
            }
            MessageBox.Show("检查完毕");
        }

        /// <summary>
        /// 提取XML核心文件
        /// </summary>
        private void getxml_button_Click(object sender, EventArgs e)
        {
            if (!Directory.Exists(xPath)) return;
            string current;
            List<string> list;
            switch (index)
            {
                case 0:
                    current = Directory.GetCurrentDirectory() + @"\日月";
                    list = new List<string>(SetRiyuePath());
                    GetXml();
                    InfoText("********提取日月核心文件********");
                    break;

                case 1:
                    current = Directory.GetCurrentDirectory() + @"\决斗";
                    list = new List<string>(SetJuedouPath());
                    GetXml();
                    InfoText("********提取决斗核心文件********");
                    break;

                case 2:
                    current = Directory.GetCurrentDirectory() + @"\新喵喵";
                    list = new List<string>(SetXinmiaomiaoPath());
                    GetXml();
                    InfoText("********提取新喵喵核心文件********");
                    break;

                case 3:
                    current = Directory.GetCurrentDirectory() + @"\新逆袭";
                    list = new List<string>(SetXinnixiPath());
                    GetXml();
                    InfoText("********提取新逆袭核心文件********");
                    break;

                case 4:
                    current = Directory.GetCurrentDirectory() + @"\新世代";
                    list = new List<string>(SetXinshidaiPath());
                    GetXml();
                    InfoText("********提取新世代核心文件********");
                    break;

                case 5:
                    current = Directory.GetCurrentDirectory() + @"\日月通用";
                    list = new List<string>(SetRiyuePath());
                    GetXml();
                    InfoText("********提取日月通用核心文件********");
                    break;
            }
            void GetXml()
            {
                if (XPath_textBox.Text == current) return;
                if (Directory.Exists(current)) Directory.Delete(current, true);
                Directory.CreateDirectory(current);
                list.AddRange(pathList);
                foreach (var item in list)
                {
                    string newfile = item.Replace(xPath, "");
                    if (!String.IsNullOrEmpty(newfile)) File.Copy(item, current + newfile);
                }
                MessageBox.Show("请在下个对话框选择 “确定” 更改文件地址，确保下次打开软件时可以自动读取提取出来的XML文件，如果XML文件有更新，请再从新提取最新文件");
                XPath_textBox.Text = current;
            }
        }

        /// <summary>
        /// 输出上次提取时间
        /// </summary>
        private void timebutton_Click(object sender, EventArgs e)
        {
            string current;
            switch (index)
            {
                case 0:
                    current = Directory.GetCurrentDirectory() + @"\日月\pets.xml";
                    GetTime("日月");
                    break;

                case 1:
                    current = Directory.GetCurrentDirectory() + @"\决斗\pets.xml";
                    GetTime("决斗");
                    break;

                case 2:
                    current = Directory.GetCurrentDirectory() + @"\新喵喵\pets.xml";
                    GetTime("新喵喵");
                    break;

                case 3:
                    current = Directory.GetCurrentDirectory() + @"\新逆袭\pets.xml";
                    GetTime("新逆袭");
                    break;

                case 4:
                    current = Directory.GetCurrentDirectory() + @"\新世代\pets.xml";
                    GetTime("新世代");
                    break;

                case 5:
                    current = Directory.GetCurrentDirectory() + @"\日月通用\pets.xml";
                    GetTime("日月通用");
                    break;
            }
            void GetTime(string name)
            {
                if (!File.Exists(current))
                {
                    InfoText("无提取时间记录");
                    return;
                }
                DateTime time = File.GetCreationTime(current);
                InfoText(name + " 最后提取时间为：" + time.ToString());
            }
        }

        /// <summary>
        /// 清空提示内容
        /// </summary>
        private void Clearinfo_button_Click(object sender, EventArgs e)
        {
            info_richTextBox.Clear();
        }

        /// <summary>
        /// 清空表格内容
        /// </summary>
        private void ClearlistView_button_Click(object sender, EventArgs e)
        {
            this.X_listView.BeginUpdate();
            this.ab_listView.BeginUpdate();
            this.X_listView.Clear();
            this.ab_listView.Clear();
            this.X_listView.EndUpdate();
            this.ab_listView.EndUpdate();
        }


        /// <summary>
        /// 修改地址库文件地址
        /// </summary>
        void ChangePath()
        {
            xmlDoc = new XmlDocument();
            xmlDoc.Load(oldPath);
            XmlElement root = xmlDoc.DocumentElement;
            XmlNodeList nodeList = root.ChildNodes;
            foreach (XmlNode item in nodeList)
            {
                string id = item.Attributes["ID"].Value;
                if (id == index.ToString())
                {
                    string temp = item.ChildNodes.Item(0).InnerText;
                    if (temp != xPath)
                    {
                        DialogResult result = MessageBox.Show("地址变更，是否保存新地址？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                        if (result == DialogResult.OK)
                        {
                            item.ChildNodes.Item(0).InnerText = xPath;
                            InfoText(id + " 新增地址：" + xPath);
                        }
                    }
                }
            }
            xmlDoc.Save(oldPath);
        }


        /// <summary>
        /// 读取 pets 表
        /// </summary>
        void LoadPet()
        {
            XmlTextReader petReader = null;
            try
            {
                petReader = new XmlTextReader(petPath);
                petReader.WhitespaceHandling = WhitespaceHandling.None;
                petTypeDic = GetTypeDic();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.StackTrace);
            }

            //精灵ID + 系列ID
            object obj = Activator.CreateInstance(types);
            string petId = null;
            string seriseId = null;
            string nextPetId = null;
            psIDTable = new Hashtable();

            //系列ID + 精灵类的实例引用
            petSeriseTable = new Hashtable();
            List<object> petInstanceList ;

            if (index == 3)
            {
                while (petReader.Read())
                {
                    if (petReader.Depth == 2 & petReader.NodeType == XmlNodeType.Element)
                    {
                        string nodeName = petReader.Name;

                        if (petTypeDic.ContainsKey(nodeName))
                        {
                            switch (nodeName)
                            {
                                case "petId":
                                    petId = petReader.ReadString();
                                    petTypeDic[nodeName].SetValue(obj, petId); //设置 petId 的值
                                    break;

                                case "nextPetId":
                                    nextPetId = petReader.ReadString();
                                    petTypeDic[nodeName].SetValue(obj, nextPetId); //设置 nextPetId 的值
                                    break;

                                default:
                                    petTypeDic[nodeName].SetValue(obj, petReader.ReadString()); //设置其他字段的值
                                    break;
                            }
                        }
                    }
                    if (petReader.Depth == 1 & petReader.NodeType == XmlNodeType.EndElement)
                    {
                        if (!psIDTable.ContainsKey(petId))
                        {
                            if (!petSeriseTable.ContainsKey(nextPetId)) //如果 nextPetId 不存在
                            {
                                petSeriseTable.Add(petId, nextPetId);
                            }
                            else //如果 nextPetId 存在
                            {
                                InfoText("pets/nextPetId 重复：" + nextPetId);
                            }
                            psIDTable.Add(petId, obj);
                        }
                        else InfoText("petId 重复：" + petId);
                        
                        obj = Activator.CreateInstance(types);
                    }
                }
            }
            else
            {
                while (petReader.Read())
                {
                    if (petReader.Depth == 2 & petReader.NodeType == XmlNodeType.Element)
                    {
                        string nodeName = petReader.Name;

                        if (petTypeDic.ContainsKey(nodeName))
                        {
                            switch (nodeName)
                            {
                                case "petId":
                                    petId = petReader.ReadString();
                                    petTypeDic[nodeName].SetValue(obj, petId); //设置 petId 的值
                                    break;

                                case "serise":
                                    seriseId = petReader.ReadString();
                                    petTypeDic[nodeName].SetValue(obj, seriseId); //设置 serise 的值
                                    break;

                                default:
                                    petTypeDic[nodeName].SetValue(obj, petReader.ReadString()); //设置其他字段的值
                                    break;
                            }
                        }
                    }
                    if (petReader.Depth == 1 & petReader.NodeType == XmlNodeType.EndElement)
                    {
                        if (!petSeriseTable.ContainsKey(seriseId)) //如果 系列ID 不存在
                        {
                            petInstanceList = new List<object>();
                            petInstanceList.Add(obj);
                            petSeriseTable.Add(seriseId, petInstanceList);
                        }
                        else //如果 系列ID 存在
                        {
                            (petSeriseTable[seriseId] as List<object>).Add(obj);
                        }
                        psIDTable.Add(petId, seriseId);
                        obj = Activator.CreateInstance(types);
                    }
                }
            }
            petReader.Close();
        }

        /// <summary>
        /// 读取 pet 表 获取精灵和精灵名称
        /// </summary>
        void LoadPetName()
        {
            try
            {
                if (index == 3) petNameHK = GetXmlXtoY(petPath, 4, 0);
                else petNameHK = GetXmlXtoY(petPath, 3, 0);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.StackTrace);
            }
        }

        /// <summary>
        /// 读取 ability（种族值） 表
        /// </summary>
        void LoadAbility()
        {
            XmlTextReader abilityReader = null;
            try
            {
                abilityReader = new XmlTextReader(abilityPath);
                abilityReader.WhitespaceHandling = WhitespaceHandling.None;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.StackTrace);
            }
            
            abilityHK = new HashK<string, Ability>();
            Ability ability = new Ability();
            string petAbilityId = null;
            while (abilityReader.Read())
            {
                if (abilityReader.Depth == 2 & abilityReader.NodeType == XmlNodeType.Element)
                {
                    string nodeName =  abilityReader.Name;
                    switch (nodeName)
                    {
                        case "petAbilityId":
                            petAbilityId = abilityReader.ReadString();
                            break;

                        case "hp":
                            ability.hp = abilityReader.ReadString();
                            break;

                        case "physicalDamage":
                            ability.physicalDamage = abilityReader.ReadString();
                            break;

                        case "physicalDefence":
                            ability.physicalDefence = abilityReader.ReadString();
                            break;

                        case "specialDamage":
                            ability.specialDamage = abilityReader.ReadString();
                            break;

                        case "specialDefence":
                            ability.specialDefence = abilityReader.ReadString();
                            break;

                        case "speed":
                            ability.speed = abilityReader.ReadString();
                            break;
                    }
                }
                if (abilityReader.Depth == 1 & abilityReader.NodeType == XmlNodeType.EndElement)
                {
                    if (abilityHK.ContainsKey(petAbilityId)) InfoText("petAbilityId重复：" + petAbilityId);
                    else
                    {
                        abilityHK.Add(petAbilityId, ability);
                        ability = new Ability();
                    }
                }
            }
            abilityReader.Close();
        }

        /// <summary>
        /// 读取 技能ID 对应的技能表
        /// </summary>
        void LoadSkill()
        {
            XmlTextReader growSkillReader = null;
            XmlTextReader studySkillReader = null;
            try
            {
                //成长技能
                growSkillReader = new XmlTextReader(growSkillPath);
                growSkillReader.WhitespaceHandling = WhitespaceHandling.None;

                //学习机
                studySkillReader = new XmlTextReader(studySkillPath);
                studySkillReader.WhitespaceHandling = WhitespaceHandling.None;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.StackTrace);
            }

            gskillHK = new HashK<string, bool>();
            sskillHK = new HashK<string, bool>();

            string skill = "";
            XmlTextReader reader = null;
            HashK<string, bool> tskillHK = null;
            HashSet<string> hs = new HashSet<string>();
            HashK<string, HashSet<string>> tempHK = null;

            void CheckXml(string temp)
            {
                if (skill != temp)
                {
                    skill = temp;

                    //判断 SkillId 是否添加进 tempHK <str/set>
                    if (tempHK.ContainsKey(skill)) hs = tempHK.GetTvalue(skill);
                    else
                    {
                        //没添加过 SkillId ：
                        hs = new HashSet<string>();
                        tempHK.Add(skill, hs);
                    }

                    //判断 SkillId 是否 没 被添加进 skillHK <str/boo> 
                    if (!tskillHK.ContainsKey(skill)) tskillHK.Add(skill, true);
                }
            }

            for (int i = 0; i < 2; i++)
            {
                string name = "";
                switch (i)
                {
                    case 0:
                        name = "growSkill";
                        reader = growSkillReader;
                        tskillHK = gskillHK;
                        tempHK = new HashK<string, HashSet<string>>();
                        break;

                    case 1:
                        name = "studySkill";
                        reader = studySkillReader;
                        tskillHK = sskillHK;
                        tempHK = new HashK<string, HashSet<string>>();
                        break;
                }
                while (reader.Read())
                {
                    if (reader.Depth == 2 & reader.NodeType == XmlNodeType.Element)
                    {
                        string temp = reader.ReadString();
                        switch (reader.Name)
                        {
                            case "growSkillId":
                                CheckXml(temp);
                                break;

                            case "studySkillId":
                                CheckXml(temp);
                                break;

                            case "skillId":
                                //判断 skillId 是否 未 被添加过
                                if (!hs.Add(temp))
                                {
                                    //添加过：
                                    InfoText(name + ": " + skill + " ，ID重复： " + temp); //输出提示
                                    tskillHK[skill] = false; // skillHK <str/boo>，growSkillId 对应的值改成 false
                                }
                                break;
                        }
                    }
                }
                reader.Close();
            }
        }

        /// <summary>
        /// 读取 日月 pmMove（所有技能） 表
        /// </summary>
        void LoadPmMove()
        {
            try
            {
                if (index == 1 || index == 2)
                {
                    pmMoveHK = GetXmlXtoY(pmMovePath, 3);
                    HashK<string, string> studySkillK = GetXmlXtoY(pmMovePath, 2, 3);
                    foreach (DictionaryEntry study in studySkillK)
                    {
                        pmMoveHK.Add(study.Key, study.Value);
                    }
                    pmMoveHK.Remove("0");
                }
                else
                {
                    pmMoveHK = GetXmlXtoY(pmMovePath, 2);
                    HashK<string, string> studySkillK = GetXmlXtoY(pmMovePath, 1, 2);
                    foreach (DictionaryEntry study in studySkillK)
                    {
                        pmMoveHK.Add(study.Key, study.Value);
                    }
                    pmMoveHK.Remove("0");
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.StackTrace);
            }
        }

        /// <summary>
        /// 读取 pmAbility（所有特性） 表
        /// </summary>
        void LoadPmAbility( )
        {
            try
            {
                pmAbilityHK = GetXmlXtoY(pmAbilityPath, 1);
            }
            catch (Exception e)
            {
                 MessageBox.Show(e.StackTrace);
            }
        }

        /// <summary>
        /// 读取 items（所有物品） 表
        /// </summary>
        void LoadItems()
        {
            try
            {
                itemsHK = GetXmlXtoY(itemsPath, 1);

            }
            catch (Exception e)
            {
                MessageBox.Show(e.StackTrace);
            }
            
        }

        /// <summary>
        /// 读取 starCondition（升星条件） 表
        /// </summary>
        void LoadStarCondition()
        {
            try
            {
                if (index == 4)
                {
                    using (XmlTextReader reader = new XmlTextReader(starConditionPath))
                    {
                        reader.WhitespaceHandling = WhitespaceHandling.None;
                        starCondition2HK = new HashK<string, StarCondition>();
                        StarCondition starCondition = new StarCondition();
                        string starIncreaseCondition = "";
                        while (reader.Read())
                        {
                            reader.ReadToFollowing("starIncreaseCondition");
                            starIncreaseCondition = reader.ReadString();

                            reader.ReadToFollowing("starUpgradeNextId");
                            starCondition.starUpgradeNextId = reader.ReadString();

                            reader.ReadToFollowing("starContentId_1");
                            starCondition.starContentId_1 = reader.ReadString();

                            if (reader.EOF == false)
                            {
                                if (starCondition2HK.ContainsKey(starIncreaseCondition))
                                {
                                    InfoText("starCondition/starIncreaseCondition 重复：" + starIncreaseCondition);
                                }
                                else
                                {
                                    starCondition2HK.Add(starIncreaseCondition, starCondition);
                                    starCondition = new StarCondition();
                                }
                            }
                        }
                    }
                }
                else starConditionHK = GetXmlXtoY(starConditionPath, 1);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.StackTrace);
            }
        }

        /// <summary>
        /// 读取 starItemList（升星材料） 表 日月
        /// </summary>
        void LoadStarItemList()
        {
            try
            {
                using (XmlTextReader reader = new XmlTextReader(starItemListPath))
                {
                    reader.WhitespaceHandling = WhitespaceHandling.None;
                    starItemListHK = new HashK<string, StarItemList>();
                    HashSet<string> set = new HashSet<string>();
                    StarItemList itemList;
                    string itemListId = "";
                    string item1_id = "";
                    string item2_id = "";
                    while (reader.Read())
                    {
                        reader.ReadToFollowing("itemListId");
                        itemListId = reader.ReadString();

                        reader.ReadToFollowing("item1_id");
                        item1_id = reader.ReadString();

                        reader.ReadToFollowing("item2_id");
                        item2_id = reader.ReadString();

                        if (set.Add(itemListId))
                        {
                            itemList = new StarItemList();
                            itemList.item1_id = item1_id;
                            itemList.item2_id = item2_id;
                            starItemListHK.Add(itemListId, itemList);
                        }
                        else InfoText("starItemList/itemListId重复：" + itemListId);
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.StackTrace);
            }
        }

        /// <summary>
        /// 读取 starContent 表（升星节点消耗） 决斗/新喵喵
        /// </summary>
        void LoadStarContent()
        {
            try
            {
                if (index == 4) starContentHK = GetXmlXtoY(starContentPath, 7);
                else starContentHK = GetXmlXtoY(starContentPath, 5);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.StackTrace);
            }
        }

        /// <summary>
        /// 读取 starLevelCost 表（升星材料） 决斗/新喵喵/新世代
        /// </summary>
        void LoadStarLevelCost()
        {
            try
            {
                using (XmlTextReader reader = new XmlTextReader(starLevelCostPath))
                {
                    reader.WhitespaceHandling = WhitespaceHandling.None;
                    starLevelCostHK = new HashK<string, string>();
                    StringBuilder builder = new StringBuilder();
                    HashSet<string> set = new HashSet<string>();
                    string starLevelCostId = "";
                    string item_2 = "";
                    string item_3 = "";
                    while (reader.Read())
                    {
                        reader.ReadToFollowing("starLevelCostId");
                        starLevelCostId = reader.ReadString();

                        reader.ReadToFollowing("item_2");
                        item_2 = reader.ReadString();

                        reader.ReadToFollowing("item_3");
                        item_3 = reader.ReadString();

                        if (reader.EOF == false)
                        {
                            if (set.Add(starLevelCostId))
                            {
                                if (builder.Length != 0) builder.Clear();
                                builder.Append(item_2 + "," + item_3);
                                starLevelCostHK.Add(starLevelCostId, builder.ToString());
                            }
                            else InfoText("starLevelCost / starLevelCostId 重复：" + starLevelCostId);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.StackTrace);
            }
        }

        /// <summary>
        /// 读取 pmCharacteristic（普通特性索引） 表
        /// </summary>
        void LoadPmCharacteristic()
        {
            try
            {
                using (XmlTextReader reader = new XmlTextReader(pmCharacteristicPath))
                {
                    reader.WhitespaceHandling = WhitespaceHandling.None;
                    pmCharacteristicHK = new HashK<string, StringBuilder>();
                    HashK<string, HashSet<string>> hashK = new HashK<string, HashSet<string>>();
                    HashSet<string> set;
                    StringBuilder builder;
                    string pokeId = "";
                    string characteristicId = "";
                    while (reader.Read())
                    {
                        reader.ReadToFollowing("pokeId");
                        pokeId = reader.ReadString();

                        reader.ReadToFollowing("characteristicId");
                        characteristicId = reader.ReadString();

                        if (reader.EOF == false)
                        {
                            if (!pmCharacteristicHK.ContainsKey(pokeId))
                            {
                                set = new HashSet<string>();
                                set.Add(characteristicId);
                                builder = new StringBuilder();
                                builder.Append(characteristicId);
                                hashK.Add(pokeId, set);
                                pmCharacteristicHK.Add(pokeId, builder);
                            }
                            else
                            {
                                builder = pmCharacteristicHK.GetTvalue(pokeId);
                                set = hashK.GetTvalue(pokeId);
                                builder.Append("," + characteristicId);
                                if (!set.Add(characteristicId)) InfoText("pmCharacteristic/pokeId 出现重复特性：" + pokeId);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.StackTrace);
            }
        }

        /// <summary>
        /// 读取 evolutionCondition（进化条件） 表
        /// </summary>
        void LoadEvolutionCondition()
        {
            try
            {
                using (XmlTextReader reader = new XmlTextReader(evolutionConditionPath))
                {
                    reader.WhitespaceHandling = WhitespaceHandling.None;
                    evolutionConditionHK = new HashK<string, string>();
                    HashSet<string> set = new HashSet<string>();
                    StringBuilder builder = new StringBuilder();
                    string evolutionConditionId = "";
                    string itemId1 = "";
                    string itemId2 = "";
                    while (reader.Read())
                    {
                        reader.ReadToFollowing("evolutionConditionId");
                        evolutionConditionId = reader.ReadString();

                        reader.ReadToFollowing("itemId1");
                        itemId1 = reader.ReadString();

                        reader.ReadToFollowing("itemId2");
                        itemId2 = reader.ReadString();
                        if (reader.EOF == false)
                        {
                            if (set.Add(evolutionConditionId))
                            {
                                if (builder.Length!=0) builder.Clear();
                                builder.Append(itemId1 + "," + itemId2);
                                evolutionConditionHK.Add(evolutionConditionId, builder.ToString());
                            }
                            else InfoText("evolutionCondition/evolutionConditionId重复：" + evolutionConditionId);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.StackTrace);
            }
        }

        /// <summary>
        /// 读取 resetEvolutionList（进化石返还） 表 日月
        /// </summary>
        void LoadResetEvolutionList()
        {
            try
            {
                using (XmlTextReader reader = new XmlTextReader(resetEvolutionListPath))
                {
                    reader.WhitespaceHandling = WhitespaceHandling.None;
                    resetEvolutionListHK = new HashK<string, ResetEvolutionList>();
                    HashSet<string> resetEvolution_Set = new HashSet<string>();
                    HashSet<string> set = new HashSet<string>();
                    StringBuilder buff;
                    ResetEvolutionList reset = new ResetEvolutionList();
                    string resetEvolution = "";
                    string awakenItemId_1 = "";
                    string awakenItemId_2 = "";
                    string resetPokeNumber = "";
                    while (reader.Read())
                    {
                        reader.ReadToFollowing("resetEvolution"); //进化石返还ID
                        resetEvolution = reader.ReadString();

                        reader.ReadToFollowing("awakenItemId_1"); //进化材料ID_1
                        awakenItemId_1 = reader.ReadString();

                        reader.ReadToFollowing("awakenItemId_2"); //进化材料ID_2
                        awakenItemId_2 = reader.ReadString();

                        reader.ReadToFollowing("resetPokeNumber"); //重置返还额外3阶精灵个数
                        resetPokeNumber = reader.ReadString();

                        if (reader.EOF == false)
                        {
                            //判断 key ID 是否能添加进 set 中
                            if (resetEvolution_Set.Add(resetEvolution)) //能添加的表明是新的
                            {
                                reset.awakenItemId_1 = awakenItemId_1;
                                reset.awakenItemId_2 = awakenItemId_2;
                                buff = new StringBuilder();
                                buff.Append(resetPokeNumber);
                                reset.resetPokeNumber = buff;
                                resetEvolutionListHK.Add(resetEvolution, reset);
                                reset = new ResetEvolutionList();
                                set.Clear(); 
                            }
                            else //无法添加的说明是重复的
                            {
                                ResetEvolutionList resettemp = resetEvolutionListHK.GetTvalue(resetEvolution);
                                resettemp.resetPokeNumber.Append(", " + resetPokeNumber);
                                if (resettemp.awakenItemId_1 != awakenItemId_1)
                                {
                                    if (set.Add(awakenItemId_1))
                                    {
                                        InfoText(String.Format("resetEvolutionList/{0}/Id_1不一致：{1}", resetEvolution, awakenItemId_1));
                                    }
                                }
                                if (resettemp.awakenItemId_2 != awakenItemId_2)
                                {
                                    if (set.Add(awakenItemId_2))
                                    {
                                        InfoText(String.Format("resetEvolutionList/{0}/Id_2不一致：{1}", resetEvolution, awakenItemId_2));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.StackTrace);
            }
        }

        /// <summary>
        /// 读取 PokeCharacter（性格洗练）表 决斗
        /// </summary>
        void LoadPokeCharacter()
        {
            try
            {
                pokeCharacterClearHK = GetXmlXtoY(pokeCharacterClearPath, 1);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.StackTrace);
            }
        }

        /// <summary>
        /// 读取 megaLvSys（Mega强化11级特性）表 决斗
        /// </summary>
        void LoadMegaLvSys()
        {
            try
            {
                using (XmlTextReader reader = new XmlTextReader(megaLvSysPath))
                {
                    reader.WhitespaceHandling = WhitespaceHandling.None;
                    megaLvSysHK = new HashK<string, string>();
                    HashSet<string> set = new HashSet<string>();
                    string mID = "";
                    string vID = "";
                    while (reader.Read())
                    {
                        if (reader.Depth == 2 & reader.NodeType == XmlNodeType.Element)
                        {
                            reader.ReadToFollowing("megaLv");
                            if (reader.ReadString() == "11")
                            {
                                reader.ReadToFollowing("valueNum");
                                vID = reader.ReadString();
                                reader.ReadToFollowing("megaStrengthenId");
                                mID = reader.ReadString();
                                if (set.Add(mID)) megaLvSysHK.Add(mID, vID);
                                else InfoText("megaLvSys/megaStrengthenId重复：" + mID);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.StackTrace);
            }
        }

        /// <summary>
        /// 读取 drop 表（掉落） 新逆袭/新世代
        /// </summary>
        void LoadDrop() 
        {
            try
            {
                if (index == 3) //新逆袭
                {
                    using (XmlTextReader reader = new XmlTextReader(dropPath))
                    {
                        reader.WhitespaceHandling = WhitespaceHandling.None;
                        dropHK = new HashK<string, string>();
                        string dropId = "";
                        string item_2 = "";
                        string num_2 = "";
                        while (reader.Read())
                        {
                            reader.ReadToFollowing("dropId");
                            dropId = reader.ReadString();
                            reader.ReadToFollowing("item_2");
                            item_2 = reader.ReadString();
                            if (reader.EOF == false)
                            {
                                if (item_2 == "100000015")
                                {
                                    reader.ReadToFollowing("num_2");
                                    num_2 = reader.ReadString();
                                    if (!dropHK.ContainsKey(dropId)) dropHK.Add(dropId, num_2);
                                    else InfoText("drop/dropId 重复：" + dropId);
                                }
                            }
                        }
                    }
                }
                if (index == 4)//新世代
                {
                    using (XmlTextReader reader = new XmlTextReader(dropPath))
                    {
                        reader.WhitespaceHandling = WhitespaceHandling.None;
                        dropHK = new HashK<string, string>();
                        string dropId = "";
                        string item_1 = "";
                        while (reader.Read())
                        {
                            reader.ReadToFollowing("dropId");
                            dropId = reader.ReadString();
                            if (reader.EOF == false)
                            {
                                if (dropId.Contains("162"))
                                {
                                    reader.ReadToFollowing("item_1");
                                    item_1 = reader.ReadString();
                                    if (dropHK.ContainsKey(dropId)) InfoText("drop/dropId 重复：" + dropId);
                                    else dropHK.Add(dropId, item_1);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.StackTrace);
            }
        }

        /// <summary>
        /// 读取 disintegrate 表（精灵分解） 决斗/新喵喵
        /// </summary>
        void LoadDisintegrate()
        {
            try
            {
                using (XmlTextReader reader = new XmlTextReader(disintegratePath))
                {
                    reader.WhitespaceHandling = WhitespaceHandling.None;
                    disintegrateHK = new HashK<string, Disintegrate>();
                    Disintegrate disintegrate = new Disintegrate();
                    string petId = "";
                    while (reader.Read())
                    {
                        if (reader.Depth == 2 & reader.NodeType == XmlNodeType.Element)
                        {
                            switch (reader.Name)
                            {
                                case "petId":
                                    petId = reader.ReadString();
                                    break;

                                case "material1_id":
                                    disintegrate.material1_id = reader.ReadString();
                                    break;

                                case "material1_numRange":
                                    disintegrate.material1_numRange = reader.ReadString();
                                    break;

                                case "material2_id":
                                    disintegrate.material2_id = reader.ReadString();
                                    break;

                                case "material2_numRange":
                                    disintegrate.material2_numRange = reader.ReadString();
                                    break;

                                case "material3_id":
                                    disintegrate.material3_id = reader.ReadString();
                                    break;

                                case "material3_numRange":
                                    disintegrate.material3_numRange = reader.ReadString();
                                    break;

                                case "material4_id":
                                    disintegrate.material4_id = reader.ReadString();
                                    break;

                                case "material4_numRange":
                                    disintegrate.material4_numRange = reader.ReadString();
                                    break;

                                case "material5_id":
                                    disintegrate.material5_id = reader.ReadString();
                                    break;

                                case "material5_numRange":
                                    disintegrate.material5_numRange = reader.ReadString();
                                    break;
                            }
                        }
                        if (reader.Depth == 1 & reader.NodeType == XmlNodeType.EndElement)
                        {
                            if (!disintegrateHK.ContainsKey(petId))
                            {
                                disintegrateHK.Add(petId, disintegrate);
                                disintegrate = new Disintegrate();
                            }
                            else InfoText("disintegrate/petId 重复：" + petId);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.StackTrace);
            }
        }

        /// <summary>                                
        /// 为表格添加指定类型数据
        /// </summary>
        void SetListViewItem(object Key)
        {
            //数据更新，UI暂时挂起，直到EndUpdate绘制控件，可以有效避免闪烁并大大提高加载速度
            this.X_listView.BeginUpdate();
            this.ab_listView.BeginUpdate();

            ListViewItem lvi = new ListViewItem();
            ListViewItem lvi2 = new ListViewItem();

            //获取该类型的指定方法
            MethodInfo getShortName = types.GetMethod("GetShortName");

            //调用该类型的方法（如果有返回值需要用 object 来接收）
            object regetShortName = getShortName.Invoke(Key, null);

            //将返回值拆箱
            SortedList<int, string> chineseList = regetShortName as SortedList<int, string>;

            //获取跳转字段
            HashK<string, string[]> jumpList = GetJumpList();

            if (this.X_listView.Columns.Count == 0)
            {
                foreach (var ch in chineseList.Values)  
                {
                    if (ch == "精灵分解") this.X_listView.Columns.Add(ch, 400, HorizontalAlignment.Left);
                    else if (ch == "精灵名字") this.X_listView.Columns.Add(ch, 120, HorizontalAlignment.Left);
                    else if (ch == "特性列表") this.X_listView.Columns.Add(ch, 180, HorizontalAlignment.Left);
                    else if (ch == "升星材料") this.X_listView.Columns.Add(ch, 170, HorizontalAlignment.Left);
                    else if (ch == "进化材料") this.X_listView.Columns.Add(ch, 200, HorizontalAlignment.Left);
                    else if (ch == "返还材料") this.X_listView.Columns.Add(ch, 105, HorizontalAlignment.Left);
                    else if (ch == "返还精灵数") this.X_listView.Columns.Add(ch, 180, HorizontalAlignment.Left);
                    else if (ch == "Z技能") this.X_listView.Columns.Add(ch, 100, HorizontalAlignment.Left);
                    else if (ch == "专属技能") this.X_listView.Columns.Add(ch, 100, HorizontalAlignment.Left);
                    else if (ch == "转生属性") this.X_listView.Columns.Add(ch, 250, HorizontalAlignment.Left);
                    else this.X_listView.Columns.Add(ch, 78, HorizontalAlignment.Left);
                }
                this.X_listView.Columns.Add("End", 50, HorizontalAlignment.Left);
            }

            if (this.ab_listView.Columns.Count == 0)
            {
                string[] handle = { "精灵名称", "系列", "属性1", "属性2", "稀有",  "血量", "物攻", "物防", "特攻", "特防", "速度", "种族值", "性别", "无性", "闪光", "图鉴", "End"};
                foreach (var item in handle)
                {
                    if (index == 3)
                    {
                        if (item == "精灵名称") this.ab_listView.Columns.Add(item, 100, HorizontalAlignment.Left);
                        else if(item != "系列") this.ab_listView.Columns.Add(item, 50, HorizontalAlignment.Left);
                    }
                    else
                    {
                        if (item == "精灵名称") this.ab_listView.Columns.Add(item, 100, HorizontalAlignment.Left);
                        else this.ab_listView.Columns.Add(item, 50, HorizontalAlignment.Left);
                    }
                }
            }

            string zero = "0";
            string exception = "*异常*";
            StringBuilder stringBuilder;
            string strTemp;
            foreach (FieldInfo item in petTypeDic.Values)
            {
                void TryCatch1(string value)
                {
                    try
                    {
                        lvi.SubItems.Add(jumpList.GetTvalue(item.Name)[Int32.Parse(value)]);
                    }
                    catch (Exception)
                    {
                        lvi.SubItems.Add(exception);
                    }
                }

                void TryCatch2(string value)
                {
                    try
                    {
                        lvi2.SubItems.Add(jumpList.GetTvalue(item.Name)[Int32.Parse(value)]);
                    }
                    catch (Exception)
                    {
                        lvi2.SubItems.Add(exception);
                    }
                }

                //获取对应字段的 实例
                string itemValue = "";
                if (item.Name != "pokeCharacterClearId")
                {
                    //获取 指定类型对象 的对应字段的值
                    if (item.GetValue(Key) == null) itemValue = "";
                    else itemValue = item.GetValue(Key).ToString();
                }

                switch (item.Name)
                {
                    case "petId": //精灵ID
                        lvi.Text = itemValue;
                        break;

                    case "petName": //精灵名字
                        lvi.SubItems.Add(itemValue);
                        lvi2.Text = itemValue;
                        break;

                    case "nextPetId": //进化Id
                        if (petNameHK.ContainsValue(itemValue)) lvi.SubItems.Add(petNameHK.GetTkey(itemValue));
                        else if (itemValue == zero) lvi.SubItems.Add(zero);
                        else lvi.SubItems.Add(exception);
                        break;

                    case "prePetId": //前置Id
                        if (petNameHK.ContainsValue(itemValue)) lvi.SubItems.Add(petNameHK.GetTkey(itemValue));
                        else if (itemValue == zero) lvi.SubItems.Add(zero);
                        else lvi.SubItems.Add(exception);
                        break;

                    case "serise": //系列ID
                        lvi2.SubItems.Add(itemValue);
                        break;

                    case "element1": //属性1
                        try
                        {
                            int element1index = Int32.Parse(itemValue);
                            if (element1index < 0) lvi2.SubItems.Add("无");
                            else lvi2.SubItems.Add(itemValue + "(" + jumpList.GetTvalue(item.Name)[element1index] + ")");
                        }
                        catch (Exception)
                        {
                            lvi2.SubItems.Add(exception);
                        }
                        break;

                    case "element2": //属性2
                        try
                        {
                            int element2index = Int32.Parse(itemValue);
                            if (element2index < 0) lvi2.SubItems.Add("无");
                            else lvi2.SubItems.Add(itemValue + "(" + jumpList.GetTvalue(item.Name)[element2index] + ")");
                        }
                        catch (Exception)
                        {
                            lvi2.SubItems.Add(exception);
                        }
                        break;

                    case "petRank": //新逆袭稀有度
                        TryCatch2(itemValue);
                        break;

                    case "petRankShow": //稀有度
                        TryCatch2(itemValue);
                        break;

                    case "petAbilityId": //种族值
                        Ability ability = abilityHK.GetTvalue(itemValue);
                        try
                        {
                            lvi2.SubItems.Add(ability.hp);
                            lvi2.SubItems.Add(ability.physicalDamage);
                            lvi2.SubItems.Add(ability.physicalDefence);
                            lvi2.SubItems.Add(ability.specialDamage);
                            lvi2.SubItems.Add(ability.specialDefence);
                            lvi2.SubItems.Add(ability.speed);
                            int count = Int32.Parse(ability.hp) + Int32.Parse(ability.physicalDamage) + Int32.Parse(ability.physicalDefence) 
                                + Int32.Parse(ability.specialDamage) + Int32.Parse(ability.specialDefence) + Int32.Parse(ability.speed);
                            lvi2.SubItems.Add(count.ToString());
                        }
                        catch (Exception )
                        {
                            lvi2.SubItems.Add(exception);
                        }
                        break;

                    case "sex": //性别
                        TryCatch2(itemValue);
                        break;

                    case "isNullSex": //无性别
                        switch (itemValue)
                        {
                            case "false":
                                itemValue = zero;
                                break;

                            case "true":
                                itemValue = "1";
                                break;
                        }
                        TryCatch2(itemValue);
                        break;

                    case "flash": //是否闪光
                        TryCatch2(itemValue);
                        break;

                    case "isInPokeindex": //图鉴展示
                        TryCatch2(itemValue);
                        break;

                    case "growSkill": //成长技能
                        if (gskillHK.GetTvalue(itemValue)) lvi.SubItems.Add("技能正常");
                        else lvi.SubItems.Add(exception);
                        break;

                    case "studySkill": //学习技能
                        if (sskillHK.GetTvalue(itemValue)) lvi.SubItems.Add("技能正常");
                        else lvi.SubItems.Add(exception);
                        break;

                    case "characteristic": //普通特性
                        lvi.SubItems.Add(itemValue);
                        if (pmCharacteristicHK.ContainsKey(itemValue))
                        {
                            stringBuilder = pmCharacteristicHK.GetTvalue(itemValue);
                            string[] str = stringBuilder.ToString().Split(',');
                            StringBuilder builder = new StringBuilder();
                            for (int i = 0; i < str.Length; i++)
                            {
                                builder.Append(pmAbilityHK.GetTvalue(str[i]) + " ");
                            }
                            lvi.SubItems.Add(builder.ToString());
                        }
                        else lvi.SubItems.Add(exception);
                        break;

                    case "petUpgradeCondition": //升阶所需条件
                        lvi.SubItems.Add(itemValue);
                        break;

                    case "petStarIncreaseCondition": //日月升星
                        StringBuilder builder1 = new StringBuilder();
                        if (index == 0 || index == 3 || index == 5)
                        {
                            lvi.SubItems.Add(itemValue);
                            if (starConditionHK.ContainsKey(itemValue)& starItemListHK.ContainsKey(starConditionHK.GetTvalue(itemValue)))
                            {
                                StarItemList itemList = starItemListHK.GetTvalue(starConditionHK.GetTvalue(itemValue));

                                if (itemList.item1_id == zero) builder1.Append(itemList.item1_id);
                                else builder1.Append(itemsHK.GetTvalue(itemList.item1_id));

                                if (itemList.item2_id == zero) builder1.Append(", " + itemList.item2_id);
                                else builder1.Append(", " + itemsHK.GetTvalue(itemList.item2_id));

                                lvi.SubItems.Add(builder1.ToString());

                            }
                            else lvi.SubItems.Add(exception);                      
                        }
                        else if (index == 1 || index == 2) //决斗/新喵喵升星
                        {
                            lvi.SubItems.Add(itemValue);
                            if (starConditionHK.ContainsKey(itemValue))
                            {
                                string star = starConditionHK.GetTvalue(itemValue);
                                if (starContentHK.ContainsKey(star))
                                {
                                    string levelCostId_1 = starContentHK.GetTvalue(star);
                                    if (starLevelCostHK.ContainsKey(levelCostId_1))
                                    {
                                        strTemp = starLevelCostHK.GetTvalue(levelCostId_1);
                                        string[] staritem = strTemp.Split(',');
                                        for (int i = 0; i < staritem.Length; i++)
                                        {
                                            if (itemsHK.ContainsKey(staritem[i]))
                                            {
                                                builder1.Append(itemsHK.GetTvalue(staritem[i]) + " ");
                                            }
                                        }
                                        lvi.SubItems.Add(builder1.ToString());
                                    }
                                    else lvi.SubItems.Add(exception);
                                }
                                else lvi.SubItems.Add(exception);
                            }
                            else lvi.SubItems.Add(exception);
                        }
                        else if (index == 4) //新世代升星
                        {
                            lvi.SubItems.Add(itemValue);
                            if (starCondition2HK.ContainsKey(itemValue))
                            {
                                StarCondition starCondition =  starCondition2HK.GetTvalue(itemValue);
                                if (starContentHK.ContainsKey(starCondition.starContentId_1))
                                {
                                    string levelCostId_1 = starContentHK.GetTvalue(starCondition.starContentId_1);
                                    if (starLevelCostHK.ContainsKey(levelCostId_1))
                                    {
                                        strTemp = starLevelCostHK.GetTvalue(levelCostId_1);
                                        string[] staritem = strTemp.Split(',');
                                        for (int i = 0; i < staritem.Length; i++)
                                        {
                                            if (itemsHK.ContainsKey(staritem[i]))
                                            {
                                                builder1.Append(itemsHK.GetTvalue(staritem[i]) + " ");
                                            }
                                        }
                                    }
                                    else builder1.Append(exception + "");
 
                                    if (starCondition2HK.ContainsKey(starCondition.starUpgradeNextId))
                                    {
                                        StarCondition starCondition2 = starCondition2HK.GetTvalue(starCondition.starUpgradeNextId);
                                        if (starContentHK.ContainsKey(starCondition2.starContentId_1))
                                        {
                                            string levelCostId_2 = starContentHK.GetTvalue(starCondition2.starContentId_1);
                                            if (starLevelCostHK.ContainsKey(levelCostId_2))
                                            {
                                                strTemp = starLevelCostHK.GetTvalue(levelCostId_2);
                                                string[] staritem = strTemp.Split(',');
                                                builder1.Append(" 转：");
                                                for (int i = 0; i < staritem.Length; i++)
                                                {
                                                    if (itemsHK.ContainsKey(staritem[i]))
                                                    {
                                                        builder1.Append(itemsHK.GetTvalue(staritem[i]) + " ");
                                                    }
                                                }
                                            }
                                            else builder1.Append(exception);
                                        }
                                        else builder1.Append(exception);
                                    }
                                    else builder1.Append(exception);

                                    lvi.SubItems.Add(builder1.ToString());
                                }
                                else lvi.SubItems.Add(exception);
                            }
                            else lvi.SubItems.Add(exception);
                        }
                        else lvi.SubItems.Add(itemValue);
                        break;

                    case "evolutionCondition": //进化所需条件
                        if (itemValue == zero)
                        {
                            lvi.SubItems.Add(itemValue);
                            lvi.SubItems.Add(itemValue);
                        }
                        else
                        {
                            string[] temp = itemValue.Split(';');
                            StringBuilder evolutionConditionbuilder = new StringBuilder();
                            for (int x = 0; x < temp.Length; x++)
                            {
                                if (evolutionConditionHK.ContainsKey(temp[x]))
                                {
                                    strTemp = evolutionConditionHK.GetTvalue(temp[x]);
                                    string[] str2 = strTemp.Split(',');
                                    for (int i = 0; i < str2.Length; i++)
                                    {
                                        if (itemsHK.ContainsKey(str2[i])) evolutionConditionbuilder.Append(itemsHK.GetTvalue(str2[i]) + " ");
                                        else evolutionConditionbuilder.Append(zero + " ");
                                    }
                                }
                                else evolutionConditionbuilder.Append(exception);
                            }
                            lvi.SubItems.Add(itemValue);
                            lvi.SubItems.Add(evolutionConditionbuilder.ToString());
                        }
                        break;
                }

                if (index == 0|| index == 5) //日月&日月通用
                {
                    switch (item.Name)
                    {
                        case "resetEvolution": //日月 进化石返还
                            if (itemValue != zero & itemValue!="" & resetEvolutionListHK.ContainsKey(itemValue))
                            {
                                ResetEvolutionList reset = resetEvolutionListHK.GetTvalue(itemValue);
                                string awakenItemId;
                                stringBuilder = reset.resetPokeNumber;
                                lvi.SubItems.Add(itemValue); //进化石返还ID
                                if (reset.awakenItemId_1 == zero) awakenItemId = reset.awakenItemId_1;
                                else awakenItemId = itemsHK.GetTvalue(reset.awakenItemId_1);

                                if (reset.awakenItemId_2 == zero) awakenItemId += ", 0 ";
                                else awakenItemId += ", " + itemsHK.GetTvalue(reset.awakenItemId_2);

                                lvi.SubItems.Add(awakenItemId);
                                if (stringBuilder.ToString() == zero) lvi.SubItems.Add(zero);
                                else lvi.SubItems.Add(stringBuilder.ToString());
                            }
                            else
                            {
                                lvi.SubItems.Add(zero);
                                lvi.SubItems.Add(zero);
                                lvi.SubItems.Add(zero);
                            }
                            break;

                        case "zMove": //Z技能
                            if (pmMoveHK.ContainsKey(itemValue)) lvi.SubItems.Add(pmMoveHK.GetTvalue(itemValue));
                            else lvi.SubItems.Add(zero);
                            break;

                        case "exclusiveSkill": //日月专属技能
                            if (pmMoveHK.ContainsKey(itemValue)) lvi.SubItems.Add(pmMoveHK.GetTvalue(itemValue));
                            else lvi.SubItems.Add(zero);
                            break;

                        case "exclusiveAbility": //日月专属特性
                            if (pmAbilityHK.ContainsKey(itemValue)) lvi.SubItems.Add(pmAbilityHK.GetTvalue(itemValue));
                            else lvi.SubItems.Add(zero);
                            break;

                        case "isNotMelt": //是否究极
                            TryCatch1(itemValue);
                            break;

                        case "elementListId": //究极属性
                            if (!String.IsNullOrEmpty(itemValue)) lvi.SubItems.Add(itemValue);
                            else lvi.SubItems.Add(zero);
                            break;

                        case "legendQuestListId": //传说任务
                            lvi.SubItems.Add(itemValue);
                            break;

                        case "isInMega3Index": //融合表展示
                            TryCatch1(itemValue);
                            break;
                    }
                }

                if (index == 1) //决斗
                {
                    switch (item.Name)
                    {
                        case "zMove": //Z技能
                            if (pmMoveHK.ContainsKey(itemValue)) lvi.SubItems.Add(pmMoveHK.GetTvalue(itemValue));
                            else lvi.SubItems.Add(zero);
                            break;

                        case "pokeCharacterClearId": //性格洗练ID

                            switch (pokeCharacterClearHK.GetTvalue(lvi.Text))
                            {
                                case "170200001":
                                    lvi.SubItems.Add("稀有洗练");
                                    break;

                                case "170200002":
                                    lvi.SubItems.Add("史诗洗练");
                                    break;

                                case "170200003":
                                    lvi.SubItems.Add("传说洗练");
                                    break;

                                case "170200004":
                                    lvi.SubItems.Add("至尊洗练");
                                    break;

                                default:
                                    lvi.SubItems.Add(zero);
                                    break;
                            }
                            break;
                        case "megaStrengthenId": //M11特性
                            if (megaLvSysHK.ContainsKey(itemValue)) lvi.SubItems.Add(pmAbilityHK.GetTvalue(megaLvSysHK.GetTvalue(itemValue)));
                            else lvi.SubItems.Add(zero);
                            break;

                        case "disintegrate": //精灵分解
                            if (disintegrateHK.ContainsKey(lvi.Text))
                            {
                                Disintegrate disintegrate = disintegrateHK.GetTvalue(lvi.Text);
                                Type type = typeof(Disintegrate);
                                FieldInfo[] fieldInfo = type.GetFields();
                                StringBuilder builder3 = new StringBuilder();
                                foreach (FieldInfo info in fieldInfo)
                                {
                                    object obj = info.GetValue(disintegrate);
                                    string str = obj.ToString();
                                    if (str!="0" & str != "0,0")
                                    {
                                        if (!str.Contains(","))
                                        {
                                            if (itemsHK.ContainsKey(str)) builder3.Append(itemsHK[str].ToString());
                                            else builder3.Append(exception);
                                        }
                                        else builder3.Append(",(" + str + ") ");
                                    }

                                }
                                lvi.SubItems.Add(builder3.ToString());
                            }
                            else lvi.SubItems.Add(zero);
                            break;
                    }
                }

                if (index == 2) //新喵喵
                {
                    switch (item.Name)
                    {
                        case "dynamaxPetId": //极巨化精灵
                            if (petNameHK.ContainsValue(itemValue)) lvi.SubItems.Add(petNameHK.GetTkey(itemValue));
                            else if (itemValue == zero) lvi.SubItems.Add(zero);
                            else lvi.SubItems.Add(exception);
                            break;

                        case "wristbandLvId": //极巨腕带
                            lvi.SubItems.Add(itemValue);
                            break;

                        case "pokeCharacterClearId": //性格洗练ID

                            switch (pokeCharacterClearHK.GetTvalue(lvi.Text))
                            {
                                case "170200001":
                                    lvi.SubItems.Add("稀有洗练");
                                    break;

                                case "170200002":
                                    lvi.SubItems.Add("史诗洗练");
                                    break;

                                case "170200003":
                                    lvi.SubItems.Add("传说洗练");
                                    break;

                                case "170200004":
                                    lvi.SubItems.Add("至尊洗练");
                                    break;

                                default:
                                    lvi.SubItems.Add(zero);
                                    break;
                            }
                            break;

                        case "disintegrate": //精灵分解
                            if (disintegrateHK.ContainsKey(lvi.Text))
                            {
                                Disintegrate disintegrate = disintegrateHK.GetTvalue(lvi.Text);
                                Type type = typeof(Disintegrate);
                                FieldInfo[] fieldInfo = type.GetFields();
                                StringBuilder builder3 = new StringBuilder();
                                foreach (FieldInfo info in fieldInfo)
                                {
                                    object obj = info.GetValue(disintegrate);
                                    string str = obj.ToString();
                                    if (str != "0" & str != "0,0")
                                    {
                                        if (!str.Contains(","))
                                        {
                                            if (itemsHK.ContainsKey(str)) builder3.Append(itemsHK[str].ToString());
                                            else builder3.Append(exception);
                                        }
                                        else builder3.Append(",(" + str + ") ");
                                    }
                                }
                                lvi.SubItems.Add(builder3.ToString());
                            }
                            else lvi.SubItems.Add(zero);
                            break;
                    }
                }

                if (index == 3) //新逆袭
                {
                    switch (item.Name)
                    {
                        case "MegaPetId": //超进化ID
                            if (petNameHK.ContainsValue(itemValue)) lvi.SubItems.Add(petNameHK.GetTkey(itemValue));
                            else if (itemValue == zero) lvi.SubItems.Add(zero);
                            else lvi.SubItems.Add(exception);
                            break;

                        case "zMove": //Z技能
                            if (pmMoveHK.ContainsKey(itemValue)) lvi.SubItems.Add(pmMoveHK.GetTvalue(itemValue));
                            else lvi.SubItems.Add(zero);
                            break;

                        case "ReleaseDropId": //放生掉落
                            if (dropHK.ContainsKey(itemValue)) lvi.SubItems.Add(dropHK.GetTvalue(itemValue));
                            else lvi.SubItems.Add(zero);
                            break;
                    }
                }

                if (index == 4) //新世代
                {
                    switch (item.Name)
                    {
                        case "isNotMelt": //是否究极
                            TryCatch1(itemValue);
                            break;

                        case "isAwakenAgain": //是否转生精灵
                            TryCatch1(itemValue);
                            break;

                        case "ReleaseDropId": //放生掉落
                            if (dropHK.ContainsKey(itemValue)) lvi.SubItems.Add(itemsHK.GetTvalue(dropHK.GetTvalue(itemValue)));
                            else lvi.SubItems.Add(exception);
                            break;

                        case "awakenAgainCondition": //转生条件
                            lvi.SubItems.Add(itemValue);
                            break;

                        case "zMove": //Z技能
                            if (pmMoveHK.ContainsKey(itemValue)) lvi.SubItems.Add(pmMoveHK.GetTvalue(itemValue));
                            else lvi.SubItems.Add(zero);
                            break;

                        case "petAwakenAgainAbilityId": //转生属性
                            if (abilityHK.ContainsKey(itemValue))
                            {
                                Ability ability = abilityHK.GetTvalue(itemValue);
                                lvi.SubItems.Add("血"+ability.hp+", 物"+ability.physicalDamage + ", 防"+ability.physicalDefence+ ", 特"+ability.specialDamage+", 抗"+ability.specialDefence + ", 速" + ability.speed); 
                            }
                            else lvi.SubItems.Add(exception);
                            break;
                    }
                }
            }

            //为数据列表添加一行数据
            this.X_listView.Items.Add(lvi);
            this.ab_listView.Items.Add(lvi2);

            //结束数据处理，UI界面一次性绘制
            this.X_listView.EndUpdate();
            this.ab_listView.EndUpdate();
        }
        

        /// <summary>
        /// 输出文本信息
        /// </summary>
        void InfoText(string info)
        {
            info = info + "\n";
            info_richTextBox.AppendText(info);
        }

        /// <summary>
        /// 获取类的字段名和公共字段引用对象
        /// </summary>
        /// <param name="type">需要反射的类型</param>
        /// <returns>返回一个 key（字段名）/value（公共字段引用对象）的字典</returns>
        Dictionary<string, FieldInfo> GetTypeDic()
        {
            Dictionary<string, FieldInfo> typeInfoDic = new Dictionary<string, FieldInfo>();
            FieldInfo[] fi = types.GetFields();
            for (int i = 0; i < fi.Length; i++) typeInfoDic.Add(fi[i].Name, fi[i]);
            return typeInfoDic;
        }

        /// <summary>
        /// 获取 XML（一对一）并输出重复 ID ， key 为第一列字段
        /// </summary>
        /// <param name="path"> XML 路径</param>
        /// <param name="y"> value 所在的字段索引，key 的索引为 0 ，value 的索引从 1 开始</param>
        HashK<string, string> GetXmlXtoY(string path, int y)
        {
            XmlLoader loader = new XmlLoader(path);
            if (loader.IsRepeate()) //判断是否存在重复的 key
            {
                HashSet<string> set = loader.GetRepeate();
                string fileName = path.Replace(xPath + @"\", "");
                string nodeX = loader.NodeX;
                foreach (var item in set)
                {
                    if (item != "0") InfoText(String.Format("{0} 的 {1} 重复: {2}", fileName, nodeX, item));
                }
            }
            return loader.XtoY(y);
        }

        /// <summary>
        /// 获取 XML（一对一）并输出重复 ID ， 任意位置索引，索引从 0 开始
        /// </summary>
        /// <param name="path">XML 路径</param>
        /// <param name="x"> key 所在的字段索引 </param>
        /// <param name="y"> value 所在的字段索引 </param>
        HashK<string, string> GetXmlXtoY(string path, int x, int y)
        {
            XmlLoader loader = default;
            try
            {
                loader = new XmlLoader(path, x);
                
            }
            catch (Exception e)
            {
                MessageBox.Show(e.StackTrace);
            }

            if (loader.IsRepeate()) //判断是否存在重复的 key
            {
                HashSet<string> set = loader.GetRepeate();
                string fileName = path.Replace(xPath + @"\", "");
                string nodeX = loader.NodeX;
                foreach (var item in set)
                {
                    if (item != "0") InfoText(String.Format("{0} 的 {1} 重复: {2}", fileName, nodeX, item));
                }
            }
            return loader.AnyWhere(y);
        }

        /// <summary>
        /// 字段跳转
        /// </summary>
        /// <returns></returns>
        HashK<string, string[]> GetJumpList()
        {
            HashK<string, string[]> sl = new HashK<string, string[]>();
            string[] 属性 = { "般", "格", "飞", "毒", "地", "岩", "虫", "幽", "钢", "炎", "水", "草", "电", "超", "冰", "龙", "恶", "妖" };
            string[] 是否 = { "否", "是" };
            string[] 无性别 = { "有性", "无性" };
            string[] 性别 = { "随机", "男", "女" };
            string[] 展示 = { "不展", "展示" };
            string[] 珍稀度 = default;
            switch (index)
            {
                case 0: //日月
                    珍稀度 = new string[] { "常见", "普通", "稀有", "史诗", "传说", "至尊" }; //5
                    break;

                case 1: //决斗
                    珍稀度 =new string[] { "无", "常见", "普通", "稀有", "史诗", "传说", "至尊" };  //6
                    break;

                case 2: //新喵喵
                    珍稀度 = new string[] { "无", "常见", "普通", "稀有", "史诗", "传说", "至尊" }; //6
                    break;

                case 3: //新逆袭
                    珍稀度 = new string[] { "无", "常见", "普通", "稀有", "史诗", "传说" }; //5
                    break;

                case 4: //新世代
                    珍稀度 = new string[] { "常见", "普通", "稀有", "史诗", "传说", "至尊" }; //5
                    break;

                case 5: //通用
                    珍稀度 = new string[] { "常见", "普通", "稀有", "史诗", "传说", "至尊" }; //5
                    break;
            }
            
            sl.Add("petRankShow", 珍稀度);
            sl.Add("petRank", 珍稀度);
            sl.Add("element1", 属性);
            sl.Add("element2", 属性);
            sl.Add("sex", 性别);
            sl.Add("isNullSex", 无性别);
            sl.Add("isInPokeindex", 是否);
            sl.Add("flash", 是否);
            sl.Add("isNotMelt", 是否);
            sl.Add("isInMega3Index", 展示);
            sl.Add("isAwakenAgain", 是否);
            
            return sl;
        }

        /// <summary>
        /// 双击清空输入框中字体
        /// </summary>
        private void Name_textBox_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            Name_textBox.Clear();
        }

        /// <summary>
        /// 双击清空输入框中字体
        /// </summary>
        private void XmlName_textBox_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            XmlName_textBox.Clear();
        }

        /// <summary>
        /// 双击清空输入框中字体
        /// </summary>
        private void XmlIndex_textBox_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            XmlIndex_textBox.Clear();
        }

        /// <summary>
        /// 双击输出表格内容
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void X_listView_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            ListView.SelectedListViewItemCollection items = X_listView.SelectedItems;
            ListViewItem.ListViewSubItemCollection subitems = items[0].SubItems;
            StringBuilder builder = new StringBuilder();
            foreach (ListViewItem.ListViewSubItem item2 in subitems)
            {
                builder.Append(item2.Text+" ");
            }
            InfoText(builder.ToString());

        }
    }
}
